<script setup lang="ts">
import DoctorCard from './DoctorCard.vue'
import {useWindowSize} from '@vueuse/core'
import {getDoctorPage} from '@/services/consult'
import { onMounted, onUnmounted, ref } from 'vue'
import type {DoctorList,PageParams} from '@/types/consult'
// 在 375 宽度设备，滚动宽度为 150
// 在其他设备需要等比例设置滚动的宽度
// scrollWidth = 150 / 375 * deviceWidth 就可以适配
// const width = ref(0)
// const setWidth = () =>  width.value = window.innerWidth
// onMounted(() => {
//   setWidth()
//   window.addEventListener('resize', setWidth)
// })
// onUnmounted(()=>{
//   window.removeEventListener('resize', setWidth)
// })
const {width}=useWindowSize()
const list=ref<DoctorList>()
const pageParams=ref<PageParams>({
    current:1,
    pageSize:5
})
onMounted(async () => {
    const res=await getDoctorPage(pageParams.value)
    list.value=res.data.rows
    console.log(list.value);
    
})
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
        <van-swipe :width="(150 / 375) * width" :loop="false" :show-indicators="false">
            <van-swipe-item v-for="item in list" :key="item.id" >
                <DoctorCard :item="item"></DoctorCard>
            </van-swipe-item>
        </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
